﻿//-----------------------------------------------------------------------
// <copyright file="PivotTableCategory.cs" company="Forebrain Technology, LLC">
//
// Copyright (c) Forebrain Technology, LLC. All rights reserved.
// 
// This source code is released under the Microsoft Public License (Ms-PL).
//
// </copyright>
//-----------------------------------------------------------------------
namespace PivotCollectionTools.Data
{
    using System;
    using System.Collections.Generic;
using System.ComponentModel;

    /// <summary>
    /// Used to categorize columns into groups. Translated to a Facet Category when building
    /// the pivot collection XML from the Pivot Table.
    /// </summary>
    [Serializable]
    public class PivotTableCategory  
    {
        /// <summary>
        /// Sotarage for the <see cref="PivotTableColumn"/> objects that are in this category.
        /// </summary>
        private List<PivotTableColumn> columns;

        /// <summary>
        /// Initializes a new instance of the <see cref="PivotTableCategory"/> class.
        /// </summary>
        /// <param name="categoryName">Name of the category.</param>
        /// <param name="dataType">Type of the data.</param>
        public PivotTableCategory(string categoryName, PivotTableCellType dataType)
        {
            this.Name = categoryName;
            this.ValueType = dataType;

            this.columns = new List<PivotTableColumn>();
            this.Columns = new PivotTableColumnCollection(this.columns);

            this.Format = string.Empty;
            this.DataBound = true;
            this.IsFilterVisible = null;
            this.IsMetadataVisible = null;
            this.IsWordWheelVisible = null;
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="PivotTableCategory"/> class.
        /// </summary>
        /// <param name="categoryName">Name of the category.</param>
        public PivotTableCategory(string categoryName)
            : this(categoryName, PivotTableCellType.Text)
        {
            this.DataBound = false;
            this.Format = string.Empty;
            this.IsFilterVisible = false;
            this.IsMetadataVisible = false;
            this.IsWordWheelVisible = false;
        }

        /// <summary>
        /// Gets or sets a value indicating whether this instance is filter visible.
        /// </summary>
        /// <value>
        /// <c>true</c> if this instance is filter visible; otherwise, <c>false</c>.
        /// </value>
        [DefaultValue(false)]
        public bool? IsFilterVisible { get; set; }

        /// <summary>
        /// Gets or sets a value indicating whether this instance is word wheel visible.
        /// </summary>
        /// <value>
        /// <c>true</c> if this instance is word wheel visible; otherwise, <c>false</c>.
        /// </value>
        [DefaultValue(false)]
        public bool? IsWordWheelVisible { get; set; }

        /// <summary>
        /// Gets or sets a value indicating whether this instance is meta data visible.
        /// </summary>
        /// <value>
        /// <c>true</c> if this instance is meta data visible; otherwise, <c>false</c>.
        /// </value>
        public bool? IsMetadataVisible { get; set; }

        /// <summary>
        /// Gets or sets the name.
        /// </summary>
        /// <value>The name of the pivot table category.</value>
        public string Name { get; set; }

        /// <summary>
        /// Gets or sets the format.
        /// </summary>
        /// <value>The format of the pivot table category.</value>
        public string Format { get; set; }

        /// <summary>
        /// Gets the type of the value.
        /// </summary>
        /// <value>The type of the value.</value>
        public PivotTableCellType ValueType { get; set; }

        /// <summary>
        /// Gets or sets a value indicating whether the columns in the cateogry are bound to 
        /// a Facet in the XML. This allows for adding columns that don't relate to a Facet for an item in the
        /// Pivot XML.
        /// <example>The Image Location is not part of the XML at all. The Description, Name, and Href of an 
        /// Item are not stored as a facet.</example>
        /// </summary>
        /// <value><c>true</c> if data bound; otherwise, <c>false</c>.</value>
        public bool DataBound { get; set; }

        /// <summary>
        /// Gets the columns that are in this category.
        /// </summary>
        /// <value>The columns of the pivot table category.</value>
        public PivotTableColumnCollection Columns { get; private set; }

        /// <summary>
        /// Adds the column.
        /// </summary>
        /// <param name="pivotTableColumn">The pivot table column.</param>
        public void AddColumn(PivotTableColumn pivotTableColumn)
        {
            this.columns.Add(pivotTableColumn);
        }

        /// <summary>
        /// Removes the column.
        /// </summary>
        /// <param name="columnToRemove">The column to remove.</param>
        public void RemoveColumn(PivotTableColumn columnToRemove)
        {
            this.columns.Remove(columnToRemove);
        }

        public override string ToString()
        {
            return this.Name;
        }
    }
}
